#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>


struct addrinfo *host_serv(const char *hostname, const char *service, int family, int socktype)
{
    int n;
    struct addrinfo hints, *res;

    bzero(&hints, sizeof(hints));
    hints.ai_flags = AI_CANONNAME; /* always return canonical name */
    hints.ai_family = family;   /* AF_UNSPEC, AF_INET6, AF_INET, etc. */
    hints.ai_socktype = socktype; /* SOCK_STREAM, SOCK_DGRAM, etc. */

    if ((n = getaddrinfo(hostname, service, &hints, &res) != 0)) {
        fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(n));
        return NULL;
    }

    return res;
}

